from appium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import os
#显示等待模块
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

os.system('adb root')
cap = {
  "platformName": "Android",  # 平台名称
  "deviceName": "emulator-5554",  # 设备名称
  "appPackage": "com.kongfz.app",  # 包名
  "appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity",  # 应用actinity包名
  "noReset": True   # 不重置
}
# 生成驱动对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', cap)
#设置隐藏等待
driver.implicitly_wait(25)
#设置强制等待
sleep(15)
# #轻敲
# driver.tap([(163, 906)], 500)
# sleep(3)
# #滑动效果，向上滑动
# driver.swipe(261.687,261,307,500)
# sleep(3)
# driver.swipe(261.687,261,307,500)
# sleep(3)
# #退出应用
# driver.quit()
# #uioutomator定位元素方法
# ele = driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.kongfz.app:id/tv_book_name")')
# print(ele.get_attribute("text"))
# print(ele.get_attribute('bounds'))
#
# ele2 = driver.find_element(By.ID,'com.kongfz.app:id/tv_book_name')
# print(ele2.get_attribute("text"))
# print(ele2.get_attribute('bounds'))
#
# ele3 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'com.kongfz.app:id/tv_book_name')))
# print(ele3.get_attribute("text"))
# print(ele3.get_attribute('bounds'))
#
# ele4 = driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.kongfz.app:id/tv_book_name")')
# print(ele4.get_attribute("text"))
# print(ele4.get_attribute('bounds'))
#
# ele5 = driver.find_element_by_android_uiautomator('new UiSelector().text("线装古籍")')
# print(ele5.get_attribute("text"))
# print(ele5.get_attribute('bounds'))
#
# ele6 = driver.find_element(By.XPATH,'//android.widget.TextView[@tetx="线装古籍"]')
# print(ele6.get_attribute("text"))
# print(ele6.get_attribute('bounds'))

